$(document).ready(function() {
    var projectId = getUrlParms("projectId");
    $("input[name='stuName']").val("小红");
    $("input[name='stuNum']").val("20151000");
    $("input[name='stuSex']").val("女");
    $("input[name='academy']").val("华信软件学院");
    $("input[name='termYear']").val("2015-2016");
    $("input[name='termNum']").val("第一学期");
    $.ajax({
        url: "http://localhost:8080/project/queryProjectByProjectId",
        type: "GET",
        async: true,
        data: "projectId=" + projectId,
        dataType: "json",
        success: function (data) {
            console.log(data)
            var project=data.data.projectStudent;
            $("input[name='projectName']").val(project.projectName);
            $("input[name='projectPlatform']").val(project.projectPlatform);
            $("input[name='projectContact']").val(project.projectContactPeople);
            $("input[name='projectPhonenum']").val(project.projectPhonenum);
            $("textarea[name='projectContent']").val(project.projectContent);
            $("input[name='startDate']").val(project.projectStartDate);
            $("input[name='endDate']").val(project.projectEndtDate);
        }
    });

});

$(document).on('click', '#apply-btn', function() {
    var projectId = getUrlParms("projectId");
    var projectName=$("input[name='projectName']").val();
    var projectPlatform=$("input[name='projectPlatform']").val();
    var projectContact=$("input[name='projectContact']").val();
    var projectPhonenum=$("input[name='projectPhonenum']").val();
    var projectContent=$("textarea[name='projectContent']").val();
    var startDate=$("input[name='startDate']").val();
    var endDate=$("input[name='endDate']").val();
    var termId=1;
    var stuInfoId=1;


    console.log(startDate)
    console.log(endDate)
    console.log(projectContact)

    //封装成对象提交
    var data = {
        projectId:projectId,
        projectName:projectName,
        termId:termId,
        stuInfoId:stuInfoId,
        projectPlatform:projectPlatform,
        projectContactPeople:projectContact,
        projectPhonenum:projectPhonenum,
        projectContent:projectContent,
        projectStartDate:startDate,
        projectEndtDate:endDate,
    };
    $.ajax({
        url: "http://localhost:8080/project/updateProject",
        type: "POST",
        async: false,
        data:JSON.stringify(data),
        dataType: "json",
        contentType:"application/json",
        success:function () {
            layer.load(1, {
                shade: [0.1,'#fff'] //0.1透明度的白色背景
            });
            setTimeout(function () {
                layer.msg('更新成功')
            },1500);

            var index = parent.layer.getFrameIndex(window.name);
            setTimeout(function(){
                parent.layer.close(index)
            }, 3000);
            parent.location.reload()
        },
        error:function () {
            layer.alert("网络在开小差~再试一次吧！");
        }
    });
});


function getUrlParms(name){
    var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
    var r = window.location.search.substr(1).match(reg);
    if(r!=null)
        return unescape(r[2]);
    return null;
}

